<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>[rabbitmq]RabbitMQ原理及Linux安装 - Never Give Up</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="ZhangKQ" /><meta name="description" content="RabbitMQ原理及Linux安装 一.RabbitMQ工作原理 1.基本结构 2.名词解释 Message 消息，消息是不具名的，它由消息头和消息体组成。消息" /><meta name="keywords" content="中间件, middleware, rabbitmq" />






<meta name="generator" content="Hugo 0.92.0 with theme even" />


<link rel="canonical" href="https://blog.nevergiveup.tech/post/middleware/rabbitmq%E5%8E%9F%E7%90%86%E5%8F%8Alinux%E5%AE%89%E8%A3%85/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.b5a744db6de49a86cadafb3b70f555ab443f83c307a483402259e94726b045ff.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="[rabbitmq]RabbitMQ原理及Linux安装" />
<meta property="og:description" content="RabbitMQ原理及Linux安装 一.RabbitMQ工作原理 1.基本结构 2.名词解释 Message 消息，消息是不具名的，它由消息头和消息体组成。消息" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://blog.nevergiveup.tech/post/middleware/rabbitmq%E5%8E%9F%E7%90%86%E5%8F%8Alinux%E5%AE%89%E8%A3%85/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2018-04-12T16:37:56+08:00" />
<meta property="article:modified_time" content="2022-02-10T16:37:56+08:00" />

<meta itemprop="name" content="[rabbitmq]RabbitMQ原理及Linux安装">
<meta itemprop="description" content="RabbitMQ原理及Linux安装 一.RabbitMQ工作原理 1.基本结构 2.名词解释 Message 消息，消息是不具名的，它由消息头和消息体组成。消息"><meta itemprop="datePublished" content="2018-04-12T16:37:56+08:00" />
<meta itemprop="dateModified" content="2022-02-10T16:37:56+08:00" />
<meta itemprop="wordCount" content="5288">
<meta itemprop="keywords" content="中间件,middleware,rabbitmq," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="[rabbitmq]RabbitMQ原理及Linux安装"/>
<meta name="twitter:description" content="RabbitMQ原理及Linux安装 一.RabbitMQ工作原理 1.基本结构 2.名词解释 Message 消息，消息是不具名的，它由消息头和消息体组成。消息"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">Never Give Up</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">主页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/remark/">
        <li class="mobile-menu-item">随言碎语</li>
      </a><a href="/about/">
        <li class="mobile-menu-item">关于</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">Never Give Up</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">主页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/remark/">随言碎语</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/about/">关于</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">[rabbitmq]RabbitMQ原理及Linux安装</h1>

      <div class="post-meta">
        <span class="post-time"> 2018-04-12 </span>
        <div class="post-category">
            <a href="/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/"> 中间件 </a>
            </div>
          <span class="more-meta"> 约 5288 字 </span>
          <span class="more-meta"> 预计阅读 11 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content">
    <nav id="TableOfContents">
  <ul>
    <li><a href="#rabbitmq原理及linux安装">RabbitMQ原理及Linux安装</a>
      <ul>
        <li><a href="#一rabbitmq工作原理">一.RabbitMQ工作原理</a>
          <ul>
            <li><a href="#1基本结构">1.基本结构</a></li>
            <li><a href="#2名词解释">2.名词解释</a></li>
            <li><a href="#3消息发布接收流程">3.消息发布/接收流程</a></li>
            <li><a href="#4exchange-类型">4.Exchange 类型</a></li>
            <li><a href="#5php-amqplib使用">5.php-amqplib使用</a></li>
          </ul>
        </li>
        <li><a href="#二rabbitmq服务安装">二.RabbitMQ服务安装</a>
          <ul>
            <li><a href="#1安装rabbitmq服务端">1.安装rabbitmq服务端</a></li>
            <li><a href="#2添加环境变量">2.添加环境变量</a></li>
            <li><a href="#4安装php-rabbitmq扩展">4.安装php-rabbitmq扩展</a></li>
          </ul>
        </li>
        <li><a href="#三web工具管理">三.web工具管理</a></li>
        <li><a href="#四php-amqplib库操作rabbitmq">四.PHP-amqplib库操作RabbitMQ</a>
          <ul>
            <li><a href="#1安装php-amqplib扩展">1.安装php-amqplib扩展</a></li>
            <li><a href="#2php-amqplib使用">2.php-amqplib使用</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <h1 id="rabbitmq原理及linux安装">RabbitMQ原理及Linux安装</h1>
<h2 id="一rabbitmq工作原理">一.RabbitMQ工作原理</h2>
<h3 id="1基本结构">1.基本结构</h3>
<p><img src="/content/post/middleware/RabbitMQ%E5%8E%9F%E7%90%86%E5%8F%8ALinux%E5%AE%89%E8%A3%85/1clipboard.png" alt="img"></p>
<h3 id="2名词解释">2.名词解释</h3>
<ul>
<li>Message
消息，消息是不具名的，它由消息头和消息体组成。消息体是不透明的，而消息头则由一系列的可选属性组成，这些属性包括routing-key（路由键）、priority（相对于其他消息的优先权）、delivery-mode（指出该消息可能需要持久性存储）等。</li>
<li>Publisher
消息的生产者，也是一个向交换器发布消息的客户端应用程序。</li>
<li>Exchange
交换器，用来接收生产者发送的消息并将这些消息路由给服务器中的队列。</li>
<li>Binding
绑定，用于消息队列和交换器之间的关联。一个绑定就是基于路由键将交换器和消息队列连接起来的路由规则，所以可以将交换器理解成一个由绑定构成的路由表。</li>
<li>Queue
消息队列，用来保存消息直到发送给消费者。它是消息的容器，也是消息的终点。一个消息可投入一个或多个队列。消息一直在队列里面，等待消费者连接到这个队列将其取走。</li>
<li>Connection
网络连接，比如一个TCP连接。</li>
<li>Channel
信道，多路复用连接中的一条独立的双向数据流通道。信道是建立在真实的TCP连接内地虚拟连接，AMQP 命令都是通过信道发出去的，不管是发布消息、订阅队列还是接收消息，这些动作都是通过信道完成。因为对于操作系统来说建立和销毁 TCP 都是非常昂贵的开销，所以引入了信道的概念，以复用一条 TCP 连接。</li>
<li>Consumer
消息的消费者，表示一个从消息队列中取得消息的客户端应用程序。</li>
<li>Virtual Host
虚拟主机，表示一批交换器、消息队列和相关对象。虚拟主机是共享相同的身份认证和加密环境的独立服务器域。每个 vhost 本质上就是一个 mini 版的 RabbitMQ 服务器，拥有自己的队列、交换器、绑定和权限机制。vhost 是 AMQP 概念的基础，必须在连接时指定，RabbitMQ 默认的 vhost 是 / 。</li>
<li>Broker
表示消息队列服务器实体。</li>
</ul>
<h3 id="3消息发布接收流程">3.消息发布/接收流程</h3>
<blockquote>
<p>&mdash;-发送消息&mdash;&ndash;
1、生产者和Broker建立TCP连接(Connection)。
2、生产者和Broker建立通道(Channel)。
3、生产者通过通道消息发送给Broker，由Exchange将消息进行转发。
4、Exchange将消息转发到指定的Queue(队列)
&mdash;-接收消息&mdash;&ndash;
1、消费者和Broker建立TCP连接
2、消费者和Broker建立通道
3、消费者监听指定的Queue(队列)
4、当有消息到达Queue时Broker默认将消息推送给消费者。
5、消费者接收到消息。
发送端操作流程
1)创建连接
2)创建通道
3)声明队列
4)发送消息
接收端
1)创建连接
2)创建通道
3)声明队列
4)监听队列
5)接收消息
6)ack回复</p>
</blockquote>
<h3 id="4exchange-类型">4.Exchange 类型</h3>
<p>Exchange分发消息时根据类型的不同分发策略有区别，目前共四种类型：direct、fanout、topic、headers 。</p>
<h4 id="1direct">1.direct</h4>
<p>消息中的路由键（routing key）如果和 Binding 中的 binding key 一致， 交换器就将消息发到对应的队列中。路由键与队列名完全匹配，如果一个队列绑定到交换机要求路由键为“dog”，则只转发 routing key 标记为“dog”的消息，不会转发“dog.puppy”，也不会转发“dog.guard”等等。它是完全匹配、单播的模式。</p>
<h4 id="2fanout">2.fanout</h4>
<p>每个发到 fanout 类型交换器的消息都会分到所有绑定的队列上去。fanout 交换器不处理路由键，只是简单的将队列绑定到交换器上，每个发送到交换器的消息都会被转发到与该交换器绑定的所有队列上。很像子网广播，每台子网内的主机都获得了一份复制的消息。fanout 类型转发消息是最快的。</p>
<h4 id="3topic">3.topic</h4>
<p>topic 交换器通过模式匹配分配消息的路由键属性，将路由键和某个模式进行匹配，此时队列需要绑定到一个模式上。它将路由键和绑定键的字符串切分成单词，这些单词之间用点“.”隔开。它同样也会识别两个通配符：符号“#”和符号“<em>”。“#”匹配0个或多个单词，“</em>”匹配不多不少一个单词。例如“com.#”能匹配到“com.rabbitmq.oa”和“com.rabbitmq”；而&quot;com.&ldquo;只能匹配到“com.rabbitmq”。</p>
<h4 id="4headers">4.Headers</h4>
<p>该类型的交换器不依赖路由规则来路由消息，而是根据消息内容中的headers属性进行匹配。headers类型交换器性能差，在实际中并不常用。和 direct 交换器完全一致，但性能差很多，目前几乎用不到。</p>
<h3 id="5php-amqplib使用">5.php-amqplib使用</h3>
<h4 id="1建立生产者与mq之间的连接">1).建立生产者与mq之间的连接</h4>
<p>$conn = new AMQPStreamConnection( $host,$port,$user,$password,$vhost);
$host:  RabbitMQ服务器主机IP地址
$port:  RabbitMQ服务器端口
$user:  连接RabbitMQ服务器的用户名
$password:  连接RabbitMQ服务器的用户密码
$vhost:   连接RabbitMQ服务器的vhost（服务器可以有多个vhost，虚拟主机，类似nginx的vhost）</p>
<h4 id="2建立通道">2).建立通道</h4>
<p>$channel = $conn-&gt;channel($channel_id); //在已连接基础上建立生产者与mq之间的通道
$channel_id 信道id，不传则获取$channel[“”]信道，再无则循环$this-&gt;channle数组，
下标从1到最大信道数找第一个不是AMQPChannel对象的下标，
实例化并返回AMQPChannel对象，无则抛出异常No free channel ids</p>
<h4 id="3声明初始化交换机">3).声明初始化交换机</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback">channel-&gt;exchange_declare(exhcange_name,type,passive,durable,auto_delete);

参数：

$exhcange_name 交换器名字

$type 交换器类型

$passive  false 是否检测同名队列

durable false  交换机是否开启持久化

auto_detlete false  通道关闭后是否删除队列

(1)交换器类型

:direct(默认)，fanout, topic, 和headers

Direct:

直接交换器，工作方式类似于单播，Exchange会将消息发送完全匹配ROUTING_KEY的Queue

fanout:

广播是式交换器，不管消息的ROUTING_KEY设置为什么，Exchange都会将消息转发给所有绑定的Queue。

topic:

主题交换器，工作方式类似于组播，Exchange会将消息转发和ROUTING_KEY匹配模式相同的所有队列，比如，ROUTING_KEY为user.stock的Message会转发给绑定匹配模式为 * .stock,user.stock， * . * 和#.user.stock.#的队列。（ * 表是匹配一个任意词组，#表示匹配0个或多个词组）

headers:

消息体的header匹配（ignore）
</code></pre></td></tr></table>
</div>
</div><h4 id="4声明初始化一条队列">4).声明初始化一条队列</h4>
<p>$channel-&gt;queue_declare($name, $passive,$durable,$exclusive,$auto_delete);
name: 队列名称
passive: false   是否检测同名队列
durable: false 是否开启队列持久化
exclusive: false  队列是否可以被其他队列访问
auto_delete: true 通道关闭后是否删除队列</p>
<h4 id="5-路由绑定">5 ).路由绑定</h4>
<p>$channel-&gt;queue_bind($queueName, $exchangeName, $routingKey);
$queueName 队列名称
$exchangeName  交换机名称
$routingKey 路由键(使用通配符的路由键：符号“#”和符号“*”)</p>
<h4 id="6创建要发送的信息-可以创建多个消息">6).创建要发送的信息 ，可以创建多个消息</h4>
<p>$msg = new AMQPMessage($data,$properties)
$data  string类型 要发送的消息
$properties array类型 设置的属性，比如设置该消息持久化[‘delivery_mode’=&gt;2]</p>
<h4 id="7发送消息">7).发送消息</h4>
<p>$channel-&gt;basic_publish($msg,$exchange,$routing_key);
$msg object AMQPMessage对象
$exchange string 交换机名字<br>
$routing_key string 路由键(不使用通配符的完整路由键),如果交换机类型</p>
<h4 id="8关闭信道和链接">8).关闭信道和链接</h4>
<p>$channel-&gt;close();
$connection-&gt;close();</p>
<h4 id="9消费消息">9).消费消息</h4>
<p>$channel-&gt;basic_consume($queue,$consumer_tag,$no_local, $no_ack, $exclusive,$nowait, $callback);
$queue队列名称
$callback回调函数
（1）回调函数
$callback = function($msg){
echo &quot; [x] Received &ldquo;, $msg-&gt;body, &ldquo;\n&rdquo;;
sleep(substr_count($msg-&gt;body, &lsquo;.'));
echo &quot; [x] Done&rdquo;, &ldquo;\n&rdquo;;
};</p>
<h4 id="10监听消息一有消息立马就处理">10).监听消息，一有消息，立马就处理</h4>
<p>while(count($channel-&gt;callbacks)) {
$channel-&gt;wait();
}</p>
<h4 id="11消息确认机制-ack">11).消息确认机制 (ack)</h4>
<p>消息消费者代码
在默认情况下，消息确认机制是关闭的。现在是时候开启消息确认机制，将basic_consumer的第四个参数设置为false(true表示不开启消息确认)，并且工作进程处理完消息后发送确认消息。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"># 处理消息回调函数
$callback = function($msg){
  echo &#34; [x] Received &#34;, $msg-&gt;body, &#34;\n&#34;;
  sleep(substr_count($msg-&gt;body, &#39;.&#39;));
  echo &#34; [x] Done&#34;, &#34;\n&#34;;
  $msg-&gt;delivery_info[&#39;channel&#39;]-&gt;basic_ack($msg-&gt;delivery_info[&#39;delivery_tag&#39;]);
};
# 开启消息确认
$channel-&gt;basic_consume(&#39;task_queue&#39;, &#39;&#39;, false, false, false, false, $callback);
</code></pre></td></tr></table>
</div>
</div><h2 id="二rabbitmq服务安装">二.RabbitMQ服务安装</h2>
<h3 id="1安装rabbitmq服务端">1.安装rabbitmq服务端</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash">下载目前最新rabbitmq服务端版本：
wget https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz
wget http://dlops.langpedu.com:8091/tars/simplejson-3.15.0.tar.gz -P <span class="nv">$TOOLSDIR</span>
wget http://dlops.langpedu.com:8091/tars/rabbitmq-server-generic-unix-3.6.15.tar.xz -P <span class="nv">$TOOLSDIR</span>
php扩展 ：
wget http://pecl.php.net/get/amqp-1.9.4.tgz

<span class="c1">#基础环境定义</span>
<span class="nv">WEBDIR</span><span class="o">=</span>/data/webserver
<span class="nv">WEBSITEDIR</span><span class="o">=</span>/data/website
<span class="nv">WWWDIR</span><span class="o">=</span>/data/www
<span class="nv">TOOLSDIR</span><span class="o">=</span>/data/tools
<span class="nv">EXTDIR</span><span class="o">=</span>/data/tools/php-ext
<span class="nv">DBDIR</span><span class="o">=</span>/data/database
<span class="nv">APPDIR</span><span class="o">=</span>/data/application

<span class="nb">cd</span> <span class="nv">$TOOLSDIR</span>
xz -d rabbitmq-server-generic-unix-3.6.15.tar.xz
tar xf rabbitmq-server-generic-unix-3.6.15.tar
tar zxf simplejson-3.15.0.tar.gz
<span class="nb">cd</span> simplejson-3.15.0
python2.7 setup.py install
</code></pre></td></tr></table>
</div>
</div><h3 id="2添加环境变量">2.添加环境变量</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="nb">cd</span> <span class="nv">$TOOLSDIR</span>
mkdir -pv <span class="nv">$APPDIR</span>/
mv rabbitmq_server-3.6.15 <span class="nv">$APPDIR</span>/rabbitmq
<span class="o">(</span>
cat <span class="s">&lt;&lt; EOF
</span><span class="s">export PATH=\$PATH:$APPDIR/rabbitmq/sbin
</span><span class="s">EOF</span>
<span class="o">)</span>&gt;&gt; /etc/profile
<span class="nb">source</span> /etc/profile
3.初始化rabbitmq服务端
<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmq-server -detached
sleep <span class="m">7</span>
<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmq-plugins <span class="nb">enable</span> rabbitmq_management

<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmqctl add_user dyadmin dyadmin
<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmqctl set_user_tags dyadmin administrator
<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmqctl set_permissions -p / dyadmin <span class="s1">&#39;.*&#39;</span> <span class="s1">&#39;.*&#39;</span> <span class="s1">&#39;.*&#39;</span>

<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmqctl add_user rabbitmq rabbitmq
<span class="nv">$APPDIR</span>/rabbitmq/sbin/rabbitmqctl set_permissions -p / rabbitmq <span class="s1">&#39;.*&#39;</span> <span class="s1">&#39;.*&#39;</span> <span class="s1">&#39;.*&#39;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="4安装php-rabbitmq扩展">4.安装php-rabbitmq扩展</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="o">[</span>root@izj6c0ct64t9oyhoeow593z amqp-1.9.4<span class="o">]</span><span class="c1"># /usr/local/php7.3.10/bin/phpize </span>
Configuring <span class="k">for</span>:
PHP Api Version:         <span class="m">20180731</span>
Zend Module Api No:      <span class="m">20180731</span>
Zend Extension Api No:   <span class="m">320180731</span>
<span class="c1">#继续</span>
<span class="o">[</span>root@izj6c0ct64t9oyhoeow593z amqp-1.9.4<span class="o">]</span><span class="c1">#  ./configure \</span>
--with-php-config<span class="o">=</span>/usr/local/php7.3.10/bin/php-config <span class="se">\
</span><span class="se"></span>--with-amqp --with-librabbitmq-dir<span class="o">=</span>/usr/local/rabbitmq-c-0.9.0/
<span class="c1">#各种输出...</span>
root@izj6c0ct64t9oyhoeow593z amqp-1.9.4<span class="o">]</span><span class="c1"># make &amp;&amp; make install</span>
php.ini文件新增extension<span class="o">=</span>amqp.so
<span class="c1">#make命令执行过程中出现报错</span>
 在目录/usr/local/rabbitmq-c-0.9.0/执行命令ln -s lib64 lib
 再返回目录/usr/local/src/amqp-1.9.4执行make <span class="o">&amp;&amp;</span> make install，安装成功
</code></pre></td></tr></table>
</div>
</div><h2 id="三web工具管理">三.web工具管理</h2>
<ul>
<li>安装
rabbitmq-plugins enable rabbitmq_management</li>
<li>默认账号密码
默认账号只能在localhost等本机模式下才可登陆
guest
guest</li>
<li>添加可以远程登陆的账号(前面已初始化)
sudo rabbitmqctl add_user test 123456
sudo rabbitmqctl set_user_tags test administrator
sudo rabbitmqctl set_permissions -p / test &ldquo;.<em>&rdquo; &ldquo;.</em>&rdquo; &ldquo;.*&rdquo;</li>
<li>查看已创建用户
rabbitmqctl list_users</li>
<li>浏览器访问web管理工具
注意防火墙配置，开启15672端口
(firewall-cmd &ndash;zone=public(作用域) &ndash;add-port=80/tcp(端口和访问类型))
http://127.0.0.1:15672</li>
</ul>
<h2 id="四php-amqplib库操作rabbitmq">四.PHP-amqplib库操作RabbitMQ</h2>
<h3 id="1安装php-amqplib扩展">1.安装php-amqplib扩展</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-php" data-lang="php"><span class="nx">composer</span> <span class="k">require</span> <span class="nx">php</span><span class="o">-</span><span class="nx">amqplib</span><span class="o">/</span><span class="nx">php</span><span class="o">-</span><span class="nx">amqplib</span>
<span class="nx">或者composer</span><span class="o">.</span><span class="nx">json文件中增加</span>
<span class="s2">&#34;require&#34;</span><span class="o">:</span> <span class="p">{</span>
  <span class="s2">&#34;php-amqplib/php-amqplib&#34;</span><span class="o">:</span> <span class="s2">&#34;2.7.*&#34;</span>
<span class="p">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="2php-amqplib使用">2.php-amqplib使用</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">  1
</span><span class="lnt">  2
</span><span class="lnt">  3
</span><span class="lnt">  4
</span><span class="lnt">  5
</span><span class="lnt">  6
</span><span class="lnt">  7
</span><span class="lnt">  8
</span><span class="lnt">  9
</span><span class="lnt"> 10
</span><span class="lnt"> 11
</span><span class="lnt"> 12
</span><span class="lnt"> 13
</span><span class="lnt"> 14
</span><span class="lnt"> 15
</span><span class="lnt"> 16
</span><span class="lnt"> 17
</span><span class="lnt"> 18
</span><span class="lnt"> 19
</span><span class="lnt"> 20
</span><span class="lnt"> 21
</span><span class="lnt"> 22
</span><span class="lnt"> 23
</span><span class="lnt"> 24
</span><span class="lnt"> 25
</span><span class="lnt"> 26
</span><span class="lnt"> 27
</span><span class="lnt"> 28
</span><span class="lnt"> 29
</span><span class="lnt"> 30
</span><span class="lnt"> 31
</span><span class="lnt"> 32
</span><span class="lnt"> 33
</span><span class="lnt"> 34
</span><span class="lnt"> 35
</span><span class="lnt"> 36
</span><span class="lnt"> 37
</span><span class="lnt"> 38
</span><span class="lnt"> 39
</span><span class="lnt"> 40
</span><span class="lnt"> 41
</span><span class="lnt"> 42
</span><span class="lnt"> 43
</span><span class="lnt"> 44
</span><span class="lnt"> 45
</span><span class="lnt"> 46
</span><span class="lnt"> 47
</span><span class="lnt"> 48
</span><span class="lnt"> 49
</span><span class="lnt"> 50
</span><span class="lnt"> 51
</span><span class="lnt"> 52
</span><span class="lnt"> 53
</span><span class="lnt"> 54
</span><span class="lnt"> 55
</span><span class="lnt"> 56
</span><span class="lnt"> 57
</span><span class="lnt"> 58
</span><span class="lnt"> 59
</span><span class="lnt"> 60
</span><span class="lnt"> 61
</span><span class="lnt"> 62
</span><span class="lnt"> 63
</span><span class="lnt"> 64
</span><span class="lnt"> 65
</span><span class="lnt"> 66
</span><span class="lnt"> 67
</span><span class="lnt"> 68
</span><span class="lnt"> 69
</span><span class="lnt"> 70
</span><span class="lnt"> 71
</span><span class="lnt"> 72
</span><span class="lnt"> 73
</span><span class="lnt"> 74
</span><span class="lnt"> 75
</span><span class="lnt"> 76
</span><span class="lnt"> 77
</span><span class="lnt"> 78
</span><span class="lnt"> 79
</span><span class="lnt"> 80
</span><span class="lnt"> 81
</span><span class="lnt"> 82
</span><span class="lnt"> 83
</span><span class="lnt"> 84
</span><span class="lnt"> 85
</span><span class="lnt"> 86
</span><span class="lnt"> 87
</span><span class="lnt"> 88
</span><span class="lnt"> 89
</span><span class="lnt"> 90
</span><span class="lnt"> 91
</span><span class="lnt"> 92
</span><span class="lnt"> 93
</span><span class="lnt"> 94
</span><span class="lnt"> 95
</span><span class="lnt"> 96
</span><span class="lnt"> 97
</span><span class="lnt"> 98
</span><span class="lnt"> 99
</span><span class="lnt">100
</span><span class="lnt">101
</span><span class="lnt">102
</span><span class="lnt">103
</span><span class="lnt">104
</span><span class="lnt">105
</span><span class="lnt">106
</span><span class="lnt">107
</span><span class="lnt">108
</span><span class="lnt">109
</span><span class="lnt">110
</span><span class="lnt">111
</span><span class="lnt">112
</span><span class="lnt">113
</span><span class="lnt">114
</span><span class="lnt">115
</span><span class="lnt">116
</span><span class="lnt">117
</span><span class="lnt">118
</span><span class="lnt">119
</span><span class="lnt">120
</span><span class="lnt">121
</span><span class="lnt">122
</span><span class="lnt">123
</span><span class="lnt">124
</span><span class="lnt">125
</span><span class="lnt">126
</span><span class="lnt">127
</span><span class="lnt">128
</span><span class="lnt">129
</span><span class="lnt">130
</span><span class="lnt">131
</span><span class="lnt">132
</span><span class="lnt">133
</span><span class="lnt">134
</span><span class="lnt">135
</span><span class="lnt">136
</span><span class="lnt">137
</span><span class="lnt">138
</span><span class="lnt">139
</span><span class="lnt">140
</span><span class="lnt">141
</span><span class="lnt">142
</span><span class="lnt">143
</span><span class="lnt">144
</span><span class="lnt">145
</span><span class="lnt">146
</span><span class="lnt">147
</span><span class="lnt">148
</span><span class="lnt">149
</span><span class="lnt">150
</span><span class="lnt">151
</span><span class="lnt">152
</span><span class="lnt">153
</span><span class="lnt">154
</span><span class="lnt">155
</span><span class="lnt">156
</span><span class="lnt">157
</span><span class="lnt">158
</span><span class="lnt">159
</span><span class="lnt">160
</span><span class="lnt">161
</span><span class="lnt">162
</span><span class="lnt">163
</span><span class="lnt">164
</span><span class="lnt">165
</span><span class="lnt">166
</span><span class="lnt">167
</span><span class="lnt">168
</span><span class="lnt">169
</span><span class="lnt">170
</span><span class="lnt">171
</span><span class="lnt">172
</span><span class="lnt">173
</span><span class="lnt">174
</span><span class="lnt">175
</span><span class="lnt">176
</span><span class="lnt">177
</span><span class="lnt">178
</span><span class="lnt">179
</span><span class="lnt">180
</span><span class="lnt">181
</span><span class="lnt">182
</span><span class="lnt">183
</span><span class="lnt">184
</span><span class="lnt">185
</span><span class="lnt">186
</span><span class="lnt">187
</span><span class="lnt">188
</span><span class="lnt">189
</span><span class="lnt">190
</span><span class="lnt">191
</span><span class="lnt">192
</span><span class="lnt">193
</span><span class="lnt">194
</span><span class="lnt">195
</span><span class="lnt">196
</span><span class="lnt">197
</span><span class="lnt">198
</span><span class="lnt">199
</span><span class="lnt">200
</span><span class="lnt">201
</span><span class="lnt">202
</span><span class="lnt">203
</span><span class="lnt">204
</span><span class="lnt">205
</span><span class="lnt">206
</span><span class="lnt">207
</span><span class="lnt">208
</span><span class="lnt">209
</span><span class="lnt">210
</span><span class="lnt">211
</span><span class="lnt">212
</span><span class="lnt">213
</span><span class="lnt">214
</span><span class="lnt">215
</span><span class="lnt">216
</span><span class="lnt">217
</span><span class="lnt">218
</span><span class="lnt">219
</span><span class="lnt">220
</span><span class="lnt">221
</span><span class="lnt">222
</span><span class="lnt">223
</span><span class="lnt">224
</span><span class="lnt">225
</span><span class="lnt">226
</span><span class="lnt">227
</span><span class="lnt">228
</span><span class="lnt">229
</span><span class="lnt">230
</span><span class="lnt">231
</span><span class="lnt">232
</span><span class="lnt">233
</span><span class="lnt">234
</span><span class="lnt">235
</span><span class="lnt">236
</span><span class="lnt">237
</span><span class="lnt">238
</span><span class="lnt">239
</span><span class="lnt">240
</span><span class="lnt">241
</span><span class="lnt">242
</span><span class="lnt">243
</span><span class="lnt">244
</span><span class="lnt">245
</span><span class="lnt">246
</span><span class="lnt">247
</span><span class="lnt">248
</span><span class="lnt">249
</span><span class="lnt">250
</span><span class="lnt">251
</span><span class="lnt">252
</span><span class="lnt">253
</span><span class="lnt">254
</span><span class="lnt">255
</span><span class="lnt">256
</span><span class="lnt">257
</span><span class="lnt">258
</span><span class="lnt">259
</span><span class="lnt">260
</span><span class="lnt">261
</span><span class="lnt">262
</span><span class="lnt">263
</span><span class="lnt">264
</span><span class="lnt">265
</span><span class="lnt">266
</span><span class="lnt">267
</span><span class="lnt">268
</span><span class="lnt">269
</span><span class="lnt">270
</span><span class="lnt">271
</span><span class="lnt">272
</span><span class="lnt">273
</span><span class="lnt">274
</span><span class="lnt">275
</span><span class="lnt">276
</span><span class="lnt">277
</span><span class="lnt">278
</span><span class="lnt">279
</span><span class="lnt">280
</span><span class="lnt">281
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-php" data-lang="php"><span class="o">&lt;?</span><span class="nx">php</span>


<span class="k">namespace</span> <span class="nx">App\Http\Controllers\Test</span><span class="p">;</span>


<span class="k">use</span> <span class="nx">App\Handler\Traits\RedisTrait\ConfigCollegeTrait</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">App\Http\Controllers\Controller</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Illuminate\Http\Request</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Illuminate\Support\Facades\Log</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">Illuminate\Support\Facades\Redis</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PhpAmqpLib\Connection\AMQPStreamConnection</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PhpAmqpLib\Exchange\AMQPExchangeType</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PhpAmqpLib\Message\AMQPMessage</span><span class="p">;</span>

<span class="sd">/**
</span><span class="sd"> * RabbitMQ队列实例
</span><span class="sd"> * Class RabbitMQController
</span><span class="sd"> * @package App\Http\Controllers\Index
</span><span class="sd"> */</span>
<span class="k">class</span> <span class="nc">RabbitMQController</span> <span class="k">extends</span> <span class="nx">Controller</span>
<span class="p">{</span>
    <span class="k">use</span> <span class="nx">ConfigCollegeTrait</span><span class="p">;</span>

    <span class="k">protected</span> <span class="k">static</span> <span class="nv">$single</span><span class="p">;</span>
    <span class="k">protected</span> <span class="k">static</span> <span class="nv">$connection</span><span class="p">;</span>
    <span class="k">protected</span> <span class="k">static</span> <span class="nv">$channel</span><span class="p">;</span>
    <span class="k">protected</span> <span class="k">static</span> <span class="nv">$config</span><span class="p">;</span>

    <span class="sd">/**
</span><span class="sd">     * RabbitMQController constructor.
</span><span class="sd">     */</span>
    <span class="k">function</span> <span class="fm">__construct</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="nx">self</span><span class="o">::</span><span class="nv">$config</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">getConfig</span><span class="p">();</span>

        <span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">AMQPStreamConnection</span><span class="p">(</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;host&#39;</span><span class="p">],</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;port&#39;</span><span class="p">],</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;user&#39;</span><span class="p">],</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;password&#39;</span><span class="p">],</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;vhost&#39;</span><span class="p">]</span>
        <span class="p">);</span>

        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span><span class="o">-&gt;</span><span class="na">channel</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * @throws \Exception
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="fm">__destruct</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">closeService</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * Author: Dy
</span><span class="sd">     * @return RabbitMQController
</span><span class="sd">     * Version: 1.0.0
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">getInstance</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$single</span> <span class="o">===</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$single</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">self</span><span class="p">();</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$single</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * Author: Dy
</span><span class="sd">     * @return AMQPStreamConnection
</span><span class="sd">     * Version: 1.0.0
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">getConnection</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span> <span class="o">===</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span>

            <span class="nv">$config</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">getConfig</span><span class="p">();</span>
        
            <span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">AMQPStreamConnection</span><span class="p">(</span>
                <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;host&#39;</span><span class="p">],</span>
                <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;port&#39;</span><span class="p">],</span>
                <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;user&#39;</span><span class="p">],</span>
                <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;password&#39;</span><span class="p">]</span>
            <span class="p">);</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * Author: Dy
</span><span class="sd">     * @return \PhpAmqpLib\Channel\AMQPChannel
</span><span class="sd">     * Version: 1.0.0
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">getChannel</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span> <span class="o">===</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span><span class="o">-&gt;</span><span class="na">channel</span><span class="p">();</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * Author: Dy
</span><span class="sd">     * @return \Illuminate\Config\Repository|mixed
</span><span class="sd">     * Version: 1.0.0
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">static</span> <span class="k">function</span> <span class="nf">getConfig</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="nx">config</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * @throws \Exception
</span><span class="sd">     */</span>
    <span class="k">function</span> <span class="nf">closeService</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$connection</span><span class="o">-&gt;</span><span class="na">close</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">close</span><span class="p">();</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * 入口程序
</span><span class="sd">     * @param Request $request
</span><span class="sd">     * @return \Illuminate\Http\JsonResponse
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">index</span><span class="p">(</span><span class="nx">Request</span> <span class="nv">$request</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="c1">//请求类型:1生产者,2消费者
</span><span class="c1"></span>        <span class="nv">$type</span> <span class="o">=</span> <span class="nv">$request</span><span class="o">-&gt;</span><span class="na">input</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
        <span class="k">try</span> <span class="p">{</span>
            <span class="nv">$response</span> <span class="o">=</span> <span class="p">[];</span>
            <span class="k">switch</span> <span class="p">(</span><span class="nv">$type</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">case</span> <span class="mi">1</span><span class="o">:</span><span class="c1">#1发布消息
</span><span class="c1"></span>                    <span class="nv">$response</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">pushMessage</span><span class="p">();</span>
                    <span class="k">break</span><span class="p">;</span>
                <span class="k">case</span> <span class="mi">2</span><span class="o">:</span><span class="c1">#2消费者1
</span><span class="c1"></span>                    <span class="nv">$response</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">receiveMessage1</span><span class="p">();</span>
                    <span class="k">break</span><span class="p">;</span>
                <span class="k">case</span> <span class="mi">3</span><span class="o">:</span><span class="c1">#2消费者2
</span><span class="c1"></span>                    <span class="nv">$response</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">receiveMessage2</span><span class="p">();</span>
                    <span class="k">break</span><span class="p">;</span>
                <span class="k">default</span><span class="o">:</span>
                    <span class="k">break</span><span class="p">;</span>
            <span class="p">}</span>

            <span class="k">return</span> <span class="nx">responseSuccess</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="nv">$response</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\Exception</span> <span class="nv">$e</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">report</span><span class="p">(</span><span class="nv">$e</span><span class="p">);</span>

            <span class="nv">$returnData</span><span class="p">[</span><span class="s1">&#39;code&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$e</span><span class="o">-&gt;</span><span class="na">getCode</span><span class="p">();</span>
            <span class="nv">$returnData</span><span class="p">[</span><span class="s1">&#39;msg&#39;</span><span class="p">]</span>  <span class="o">=</span> <span class="nv">$e</span><span class="o">-&gt;</span><span class="na">getMessage</span><span class="p">();</span>
        
            <span class="k">return</span> <span class="nx">responseSuccess</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="nv">$returnData</span><span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * 发布消息
</span><span class="sd">     * @return bool
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">pushMessage</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="nv">$exchangeName</span> <span class="o">=</span> <span class="s1">&#39;my_exchange_topic&#39;</span><span class="p">;</span> <span class="c1">//交换机名
</span><span class="c1"></span>        <span class="nv">$queueName1</span>   <span class="o">=</span> <span class="s1">&#39;msg_send_queue&#39;</span><span class="p">;</span> <span class="c1">//队列名称
</span><span class="c1"></span>        <span class="nv">$queueName2</span>   <span class="o">=</span> <span class="s1">&#39;sms_send_queue&#39;</span><span class="p">;</span> <span class="c1">//队列名称
</span><span class="c1"></span>        <span class="nv">$routingKeys</span>  <span class="o">=</span> <span class="s1">&#39;sms_send.msg_send.temp_send&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>        <span class="nv">$routingKey1</span>  <span class="o">=</span> <span class="s1">&#39;#msg_send#&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>        <span class="nv">$routingKey2</span>  <span class="o">=</span> <span class="s1">&#39;#sms_send#&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>
        <span class="c1">//交换机类型
</span><span class="c1"></span>        <span class="c1">//’’  默认交换机 匿名交换器 未显示声明类型都是该类型
</span><span class="c1"></span>        <span class="c1">//fanout  扇形交换器 会发送消息到它所知道的所有队列，每个消费者获取的消息都是一致的
</span><span class="c1"></span>        <span class="c1">//headers 头部交换器
</span><span class="c1"></span>        <span class="c1">//direct 直连交换器，该交换机将会对绑定键（binding key）和路由键（routing key）进行精确匹配
</span><span class="c1"></span>        <span class="c1">//topic 话题交换器 该交换机会对路由键正则匹配，必须是*(一个单词)、#(多个单词，以.分割) 、      user.key .abc.* 类型的key
</span><span class="c1"></span>
        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">exchange_declare</span><span class="p">(</span><span class="nv">$exchangeName</span><span class="p">,</span> <span class="nx">AMQPExchangeType</span><span class="o">::</span><span class="na">TOPIC</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化交换机
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_declare</span><span class="p">(</span><span class="nv">$queueName1</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化一条队列
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_declare</span><span class="p">(</span><span class="nv">$queueName2</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化一条队列
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_bind</span><span class="p">(</span><span class="nv">$queueName1</span><span class="p">,</span> <span class="nv">$exchangeName</span><span class="p">,</span> <span class="nv">$routingKey1</span><span class="p">);</span> <span class="c1">//将队列与某个交换机进行绑定，并使用路由关键字
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_bind</span><span class="p">(</span><span class="nv">$queueName2</span><span class="p">,</span> <span class="nv">$exchangeName</span><span class="p">,</span> <span class="nv">$routingKey2</span><span class="p">);</span> <span class="c1">//将队列与某个交换机进行绑定，并使用路由关键字
</span><span class="c1"></span>
        <span class="nv">$msgBody</span> <span class="o">=</span> <span class="nx">json_encode</span><span class="p">([</span><span class="s2">&#34;name&#34;</span> <span class="o">=&gt;</span> <span class="s2">&#34;iGoo&#34;</span><span class="p">,</span> <span class="s2">&#34;age&#34;</span> <span class="o">=&gt;</span> <span class="mi">22</span><span class="p">]);</span>
        <span class="nv">$msg</span>     <span class="o">=</span> <span class="k">new</span> <span class="nx">AMQPMessage</span><span class="p">(</span><span class="nv">$msgBody</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;content_type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;text/plain&#39;</span><span class="p">,</span> <span class="s1">&#39;delivery_mode&#39;</span> <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">]);</span> <span class="c1">//生成消息
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">basic_publish</span><span class="p">(</span><span class="nv">$msg</span><span class="p">,</span> <span class="nv">$exchangeName</span><span class="p">,</span> <span class="nv">$routingKeys</span><span class="p">);</span> <span class="c1">//推送消息到某个交换机
</span><span class="c1"></span>
        <span class="k">return</span> <span class="k">true</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="sd">/**
</span><span class="sd">     * 接收消息1
</span><span class="sd">     * @throws \ErrorException
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">receiveMessage1</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="nv">$exchangeName</span> <span class="o">=</span> <span class="s1">&#39;my_exchange_topic&#39;</span><span class="p">;</span> <span class="c1">//交换机名
</span><span class="c1"></span>        <span class="nv">$queueName1</span>   <span class="o">=</span> <span class="s1">&#39;msg_send_queue&#39;</span><span class="p">;</span> <span class="c1">//队列名称
</span><span class="c1"></span>        <span class="nv">$queueName2</span>   <span class="o">=</span> <span class="s1">&#39;sms_send_queue&#39;</span><span class="p">;</span> <span class="c1">//队列名称
</span><span class="c1"></span>        <span class="nv">$routingKeys</span>  <span class="o">=</span> <span class="s1">&#39;msg_send.sms_send&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>        <span class="nv">$routingKey1</span>  <span class="o">=</span> <span class="s1">&#39;#msg_send#&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>        <span class="nv">$routingKey2</span>  <span class="o">=</span> <span class="s1">&#39;#sms_send#&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>
        <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">hset</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
        <span class="nv">$callback1</span> <span class="o">=</span> <span class="k">function</span> <span class="p">(</span><span class="nv">$msg</span><span class="p">)</span> <span class="p">{</span>
            <span class="c1">//echo &#34; [x] Received &#34;, $msg-&gt;body, &#34;\n&#34;;
</span><span class="c1"></span>            <span class="c1">//echo &#34; [x] Done&#34;, &#34;\n&#34;;
</span><span class="c1"></span>            <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">hset</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
            <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">hset</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">,</span>
                <span class="s1">&#39;msg_send_queue|&#39;</span> <span class="o">.</span> <span class="nx">date</span><span class="p">(</span><span class="s1">&#39;Y-m-d H:i:s&#39;</span><span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;|&#39;</span> <span class="o">.</span> <span class="nx">rand</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">9999</span><span class="p">),</span>
                <span class="nv">$msg</span><span class="o">-&gt;</span><span class="na">body</span> <span class="o">??</span> <span class="s1">&#39;无数据&#39;</span><span class="p">);</span>

            <span class="c1">//消息确认机制 (ack),手动确认消息是否正常消费，保证消息消费的幂等。
</span><span class="c1"></span>            <span class="nv">$msg</span><span class="o">-&gt;</span><span class="na">delivery_info</span><span class="p">[</span><span class="s1">&#39;channel&#39;</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">basic_ack</span><span class="p">(</span><span class="nv">$msg</span><span class="o">-&gt;</span><span class="na">delivery_info</span><span class="p">[</span><span class="s1">&#39;delivery_tag&#39;</span><span class="p">]);</span>
        <span class="p">};</span>

        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">exchange_declare</span><span class="p">(</span><span class="nv">$exchangeName</span><span class="p">,</span> <span class="nx">AMQPExchangeType</span><span class="o">::</span><span class="na">TOPIC</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化交换机
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_declare</span><span class="p">(</span><span class="nv">$queueName1</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化一条队列
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_bind</span><span class="p">(</span><span class="nv">$queueName1</span><span class="p">,</span> <span class="nv">$exchangeName</span><span class="p">,</span> <span class="nv">$routingKey1</span><span class="p">);</span> <span class="c1">//将队列与某个交换机进行绑定，并使用路由关键字
</span><span class="c1"></span>
        <span class="c1">#$callback 表示回调函数，传入消息参数
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">basic_consume</span><span class="p">(</span><span class="nv">$queueName1</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="nv">$callback1</span><span class="p">);</span>


        <span class="c1">#监听消息，一有消息，立马就处理
</span><span class="c1"></span>        <span class="k">while</span> <span class="p">(</span><span class="nx">count</span><span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">callbacks</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s1">&#39;rabbitmq_flag&#39;</span><span class="p">))</span> <span class="p">{</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">wait</span><span class="p">();</span>
        <span class="p">}</span>
    
        <span class="k">return</span> <span class="k">true</span><span class="p">;</span>
    <span class="p">}</span>
    
    <span class="sd">/**
</span><span class="sd">     * 接收消息2
</span><span class="sd">     * @throws \ErrorException
</span><span class="sd">     */</span>
    <span class="k">public</span> <span class="k">function</span> <span class="nf">receiveMessage2</span><span class="p">()</span>
    <span class="p">{</span>
        <span class="nv">$exchangeName</span> <span class="o">=</span> <span class="s1">&#39;my_exchange_topic&#39;</span><span class="p">;</span> <span class="c1">//交换机名
</span><span class="c1"></span>        <span class="nv">$queueName1</span>   <span class="o">=</span> <span class="s1">&#39;msg_send_queue&#39;</span><span class="p">;</span> <span class="c1">//队列名称
</span><span class="c1"></span>        <span class="nv">$queueName2</span>   <span class="o">=</span> <span class="s1">&#39;sms_send_queue&#39;</span><span class="p">;</span> <span class="c1">//队列名称
</span><span class="c1"></span>        <span class="nv">$routingKeys</span>  <span class="o">=</span> <span class="s1">&#39;msg_send.sms_send&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>        <span class="nv">$routingKey1</span>  <span class="o">=</span> <span class="s1">&#39;#msg_send#&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>        <span class="nv">$routingKey2</span>  <span class="o">=</span> <span class="s1">&#39;#sms_send#&#39;</span><span class="p">;</span> <span class="c1">//路由关键字(也可以省略)
</span><span class="c1"></span>    
        <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">hset</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
        <span class="nv">$callback2</span> <span class="o">=</span> <span class="k">function</span> <span class="p">(</span><span class="nv">$msg</span><span class="p">)</span> <span class="p">{</span>
            <span class="c1">//echo &#34; [x] Received &#34;, $msg-&gt;body, &#34;\n&#34;;
</span><span class="c1"></span>            <span class="c1">//echo &#34; [x] Done&#34;, &#34;\n&#34;;
</span><span class="c1"></span>            <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">hset</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span>
            <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">hset</span><span class="p">(</span><span class="s1">&#39;rabbitmq&#39;</span><span class="p">,</span>
                <span class="s1">&#39;sms_send_queue|&#39;</span> <span class="o">.</span> <span class="nx">date</span><span class="p">(</span><span class="s1">&#39;Y-m-d H:i:s&#39;</span><span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;|&#39;</span> <span class="o">.</span> <span class="nx">rand</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">9999</span><span class="p">),</span>
                <span class="nv">$msg</span><span class="o">-&gt;</span><span class="na">body</span> <span class="o">??</span> <span class="s1">&#39;无数据&#39;</span><span class="p">);</span>
    
            <span class="c1">//消息确认机制 (ack),手动确认消息是否正常消费，保证消息消费的幂等。
</span><span class="c1"></span>            <span class="nv">$msg</span><span class="o">-&gt;</span><span class="na">delivery_info</span><span class="p">[</span><span class="s1">&#39;channel&#39;</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">basic_ack</span><span class="p">(</span><span class="nv">$msg</span><span class="o">-&gt;</span><span class="na">delivery_info</span><span class="p">[</span><span class="s1">&#39;delivery_tag&#39;</span><span class="p">]);</span>
        <span class="p">};</span>
    
        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">exchange_declare</span><span class="p">(</span><span class="nv">$exchangeName</span><span class="p">,</span> <span class="nx">AMQPExchangeType</span><span class="o">::</span><span class="na">TOPIC</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化交换机
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_declare</span><span class="p">(</span><span class="nv">$queueName2</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">);</span> <span class="c1">//声明初始化一条队列
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">queue_bind</span><span class="p">(</span><span class="nv">$queueName2</span><span class="p">,</span> <span class="nv">$exchangeName</span><span class="p">,</span> <span class="nv">$routingKey2</span><span class="p">);</span> <span class="c1">//将队列与某个交换机进行绑定，并使用路由关键字
</span><span class="c1"></span>    
        <span class="c1">#$callback 表示回调函数，传入消息参数
</span><span class="c1"></span>        <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">basic_consume</span><span class="p">(</span><span class="nv">$queueName2</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="k">false</span><span class="p">,</span> <span class="nv">$callback2</span><span class="p">);</span>


        <span class="c1">#监听消息，一有消息，立马就处理
</span><span class="c1"></span>        <span class="k">while</span> <span class="p">(</span><span class="nx">count</span><span class="p">(</span><span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">callbacks</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">Redis</span><span class="o">::</span><span class="na">connection</span><span class="p">(</span><span class="s1">&#39;cache&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s1">&#39;rabbitmq_flag&#39;</span><span class="p">))</span> <span class="p">{</span>
            <span class="nx">self</span><span class="o">::</span><span class="nv">$channel</span><span class="o">-&gt;</span><span class="na">wait</span><span class="p">();</span>
        <span class="p">}</span>
    
        <span class="k">return</span> <span class="k">true</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></td></tr></table>
</div>
</div>
    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">ZhangKQ</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2022-02-10
        
    </span>
  </p>
  
  
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/qrcode/wechat-qr-code.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/qrcode/alipay-qr-code.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/%E4%B8%AD%E9%97%B4%E4%BB%B6/">中间件</a>
          <a href="/tags/middleware/">middleware</a>
          <a href="/tags/rabbitmq/">rabbitmq</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/middleware/rabbitmq%E5%9C%A8docker%E5%AE%89%E8%A3%85%E5%8F%8A%E4%BD%BF%E7%94%A8/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">[rabbitmq]RabbitMQ在Docker安装及使用</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/dev_language/shell/shell%E8%84%9A%E6%9C%AC%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/">
            <span class="next-text nav-default">[shell]shell脚本入门教程</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:wdyxzkq@163.com" class="iconfont icon-email" title="email"></a>
      <a href="https://github.com/dysoso" class="iconfont icon-github" title="github"></a>
      <a href="https://gitee.com/dysoso" class="iconfont icon-gitlab" title="gitlab"></a>
  <a href="https://blog.nevergiveup.tech/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://blog.nevergiveup.tech/">blog.nevergiveup.tech</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy; 
    2021 - 
    2022<span class="heart"><i class="iconfont icon-heart"></i></span><span><a href="https://beian.miit.gov.cn/">蜀ICP备2021005948号-1</a></span>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.c99b103c33d1539acf3025e1913697534542c4a5aa5af0ccc20475ed2863603b.js"></script>


<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'never-give-up', 'auto');
	ga('set', 'anonymizeIp', true);
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>







</body>
</html>
